//
//  FBFinderOrderViewStatus_One_Sale_AliPayOrWechat.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/11.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBFinderOrderViewStatus_One_Sale_AliPayOrWechat.h"
#import "PayTypeSelectedButton.h"

@interface FBFinderOrderViewStatus_One_Sale_AliPayOrWechat ()

@property (nonatomic,strong)UILabel * lab1;
@property (nonatomic,strong)UILabel * lab2;
@property (nonatomic,strong)UILabel * lab3;
@property (nonatomic,strong)UILabel * lab4;
@property (nonatomic,strong)UILabel * lab5;
@property (nonatomic,strong)UILabel * lab6;
@property (nonatomic,strong)UILabel * lab7;
@property (nonatomic,strong)UILabel * lab8;
@property (nonatomic,strong)UIView  * bgView;

@property (nonatomic,strong) UILabel * unReadOrderLab;

@end

@implementation FBFinderOrderViewStatus_One_Sale_AliPayOrWechat

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    /*
     * XX
     */
    UILabel * lab1 = [[UILabel alloc]init];
    [self setLab:lab1 withColor:RGB(30, 63, 89) andFont:28 andText:@"出售 XX" andTextAlignment:NSTextAlignmentLeft];
    [self addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
    }];
    _lab1=lab1;
    
    /*
     * 状态
     */
    UILabel * lab2 = [[UILabel alloc]init];
    [self addSubview:lab2];
    [self setLab:lab2 withColor:RGB(231, 98, 98) andFont:15 andText:@"买家已付款" andTextAlignment:NSTextAlignmentRight];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lab1.mas_centerY).offset(0);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
    }];
    _lab2=lab2;
    
    UILabel * time = [[UILabel alloc]init];
    [self addSubview:time];
    [self setLab:time withColor:RGB(30, 63, 89) andFont:12 andText:@"X分X秒" andTextAlignment:NSTextAlignmentRight];
    [time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab2.mas_bottom).offset(0);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
    }];
    _time = time;
    
    UIView * bgView = [[UIView alloc]init];
    [self addSubview:bgView];
    bgView.backgroundColor=RGB(250, 250, 250);
    bgView.layer.shadowOpacity = 0.5;// 阴影透明度
    bgView.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
    bgView.layer.shadowRadius = 3;// 阴影扩散的范围控制
    //    bgView.layer.shadowOffset = CGSizeMake(1, 1);// 阴影的范围
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(time.mas_bottom).offset(20);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(170));
    }];
    
    _bgView = bgView;
    
    NSArray * arrlogo = @[@"支付宝",@"微信-3",@"银行卡"];
    NSArray * arrname = @[@"支付宝",@"微信",@"银行卡"];
    for (int i =0 ; i<3; i++) {
        PayTypeSelectedButton * btn = [[PayTypeSelectedButton alloc]init];
        [bgView addSubview:btn];
        btn.frame = CGRectMake(0, 10+50*i, G_SCREENWIDTH-30, 50);
        btn.tag = 9004+i;
        btn.logo.image = [UIImage imageNamed:arrlogo[i]];
        btn.lab.text=arrname[i];
        btn.imgVselected.image=[UIImage imageNamed:@""];
        [btn addTarget:self action:@selector(selectedPayType:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    UILabel * lab3 = [[UILabel alloc]init];
    UILabel * lab4 = [[UILabel alloc]init];
    UILabel * lab5 = [[UILabel alloc]init];
    UILabel * lab6 = [[UILabel alloc]init];
    UILabel * lab7 = [[UILabel alloc]init];
    UILabel * lab8 = [[UILabel alloc]init];
    
    _lab3=lab3;
    _lab4=lab4;
    _lab5=lab5;
    _lab6=lab6;
    _lab7=lab7;
    _lab8=lab8;
    
    [self setLeftText:@"对方" andLab:lab3 andIndex:0 andbg:self];
    [self setLeftText:@"订单金额" andLab:lab4 andIndex:1 andbg:self];
    [self setLeftText:@"单价" andLab:lab5 andIndex:2 andbg:self];
    [self setLeftText:@"数量" andLab:lab6 andIndex:3 andbg:self];
    [self setLeftText:@"订单号" andLab:lab7 andIndex:4 andbg:self];
    [self setLeftText:@"订单时间" andLab:lab8 andIndex:5 andbg:self];
    
    
        UIButton *  btn1 = [[UIButton alloc]init];
        [self addSubview:btn1];
        [btn1 setTitleColor:ThemeColor forState:UIControlStateNormal];
        [btn1 setImage:[UIImage imageNamed:@"消息icon"] forState:UIControlStateNormal];
        btn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        btn1.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [btn1 addTarget:self action:@selector(GoToChatVC) forControlEvents:UIControlEventTouchUpInside];
        btn1.backgroundColor=RGB(255, 255, 255);
        [btn1.imageView setContentMode:UIViewContentModeScaleAspectFill];
        [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
            make.left.equalTo(self.mas_left).offset(0);
            make.width.mas_equalTo(65);
            make.height.mas_equalTo(49);
        }];
    
    
    
    UILabel * unReadOrderLab = [[UILabel alloc]init];
    [self addSubview:unReadOrderLab];
    unReadOrderLab.layer.borderColor = [UIColor whiteColor].CGColor;
    unReadOrderLab.layer.borderWidth = 1;
    [self setLab:unReadOrderLab withColor:[UIColor whiteColor] andFont:9 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    unReadOrderLab.layer.cornerRadius = 9;
    unReadOrderLab.clipsToBounds=YES;
    unReadOrderLab.backgroundColor=[UIColor redColor];
    [unReadOrderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight+9);
        make.left.equalTo(self.mas_left).offset(65/2.0+3);
        make.width.mas_equalTo(18);
        make.height.mas_equalTo(18);
    }];
    _unReadOrderLab=unReadOrderLab;
    _unReadOrderLab.hidden=YES;
    
        UIButton *  btn2 = [[UIButton alloc]init];
        [self addSubview:btn2];
        [btn2 setTitleColor:RGB(99, 140, 220) forState:UIControlStateNormal];
        [btn2 setTitle:@"申诉" forState:UIControlStateNormal];
        btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        btn2.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [btn2 addTarget:self action:@selector(shenSu) forControlEvents:UIControlEventTouchUpInside];
        btn2.backgroundColor=RGB(235, 240, 248);
        [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
            make.left.equalTo(self.mas_left).offset(65);
            make.width.mas_equalTo((G_SCREENWIDTH-65)/2.0);
            make.height.mas_equalTo(49);
        }];
        
        UIButton *  btn3 = [[UIButton alloc]init];
        [self addSubview:btn3];
        [btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn3 setTitle:@"放币" forState:UIControlStateNormal];
        btn3.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        btn3.tag = 10003;
        btn3.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [btn3 addTarget:self action:@selector(FangBi) forControlEvents:UIControlEventTouchUpInside];
        btn3.backgroundColor=RGB(99, 140, 220);
        [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
            make.right.equalTo(self.mas_right).offset(0);
            make.width.mas_equalTo((G_SCREENWIDTH-65)/2.0);
            make.height.mas_equalTo(49);
        }];
        
    
    
    
}

-(void)selectedPayType:(PayTypeSelectedButton *)btn{
//    if (self.paySelcetedBlock) {
//        self.paySelcetedBlock([NSString stringWithFormat:@"%ld",btn.tag-9000]);
//    }
//    //    btn.backgroundColor=[UIColor cyanColor];
//
//    PayTypeSelectedButton * b1,*b2;
//    if (btn.tag == 9004) {
//        b1 = [self viewWithTag:9005];
//        b2 = [self viewWithTag:9006];
//    }else if (btn.tag == 9005){
//        b1 = [self viewWithTag:9004];
//        b2 = [self viewWithTag:9006];
//    }else if (btn.tag == 9006){
//        b1 = [self viewWithTag:9004];
//        b2 = [self viewWithTag:9005];
//    }
//    b1.imgVselected.image=[UIImage imageNamed:@"选择btn-未选中"];
//    b2.imgVselected.image=[UIImage imageNamed:@"选择btn-未选中"];
//    btn.imgVselected.image=[UIImage imageNamed:@"选择btn-选中"];
}

#pragma mark-跳转消息
-(void)GoToChatVC{
    
    if (self.block) {
        self.block(FBFindorderActionType_GoToChat);
    }
    
    
}

#pragma mark-
-(void)shenSu{
    if (self.block) {
        self.block(FBFindorderActionType_ShenSu);
    }
}


#pragma mark-
-(void)FangBi{
    
    if (self.block) {
        self.block(FBFindorderActionType_FangBi);
    }
}

-(void)setLeftText:(NSString *)text1 andLab:(UILabel *)lab andIndex:(NSInteger)index  andbg:(UIView * )bg{
    CGFloat Top = index* 33 + 10;
    UILabel * left = [[UILabel alloc]init];
    [self addSubview:left];
    [self setLab:left withColor:RGB(140, 159, 173) andFont:13 andText:text1 andTextAlignment:NSTextAlignmentLeft];
    [left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_bottom).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
    
    
    [self addSubview:lab];
    [self setLab:lab withColor:RGB(30, 63, 89) andFont:13 andText:@"加载中" andTextAlignment:NSTextAlignmentRight];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_bottom).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
}


-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}

-(void)setDataSource:(FBFindorderModel *)dataSource{
    
    _dataSource = dataSource;
    if (dataSource) {
        _lab1.text=[NSString stringWithFormat:@"出售%@",self.dataSource.symbol];
        _lab3.text=[NSString stringWithFormat:@"%@",self.dataSource.bill_nickname];
        _lab4.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.amount,self.dataSource.legal];
        _lab5.text = [NSString stringWithFormat:@"%@ %@/%@",self.dataSource.price,self.dataSource.legal,self.dataSource.symbol];
        _lab6.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.volume,self.dataSource.symbol];
        _lab7.text = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
        _lab8.text = [NSString stringWithFormat:@"%@",self.dataSource.create_time];
    
        if (dataSource.payment_info) {
            NSString * paytype_id = [NSString stringWithFormat:@"%@",dataSource.payment_info[@"paytype_id"]] ;
            if ((![paytype_id containsString:@"null"]) && paytype_id.length>0) {
                
                PayTypeSelectedButton * b1= [self viewWithTag:(9000+[paytype_id integerValue])];
                b1.imgVselected.image=[UIImage imageNamed:@"选择btn-选中"];
            }
        }
    }
}

#pragma mark-设置未读消息数量
-(void)setUnReadOrderNum{
    
    FBFindorderUnReadOrder * FU = [FBFindorderUnReadOrder sharedFBFindorderUnReadOrder];
    NSLog(@"%@",self.dataSource.order_sn);
    NSString * order_sn = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
    NSString * Num = [NSString stringWithFormat:@"%@",FU.UnReadOrderDic[order_sn]];
    if ([Num integerValue]>0) {
        _unReadOrderLab.text=Num;
        _unReadOrderLab.hidden=NO;
        if ([Num integerValue]<10) {
            _unReadOrderLab.font = [UIFont boldSystemFontOfSize:9];
        }
    }else{
        _unReadOrderLab.hidden=YES;
    }
    
}

@end


